package LeetCode.month02.day50;


import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.regex.Pattern;

public class No2785 {
    public static void main(String[] args) {
        System.out.println(sortVowels("lYmpH"));
    }
    public static String sortVowels(String s) {
        List<Character> list1 =new ArrayList<>();
        List<Integer> list2 = new ArrayList<>();
        list2.add(-1);
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u'||
                    c=='A'||c=='E'||c=='I'||c=='O'||c=='U'){
                list2.add(i);
                list1.add(c);
            }
        }
        if(list1.isEmpty()) {
            return s;
        }
        list1.sort((a,b)->a-b);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < list1.size(); i++) {
            sb = sb.append(s.substring(list2.get(i)+1,list2.get(i+1))+list1.get(i));
        }
        sb = sb.append(s.substring(list2.get(list2.size()-1)+1));
        return sb.toString();

    }
}
